package top.wineye.spring.dependency.source;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ResolvableDependencyDemo {

    @Autowired
    String value;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx =
                new AnnotationConfigApplicationContext();

        ctx.register(ResolvableDependencyDemo.class);

        ctx.addBeanFactoryPostProcessor(beanFactory -> {
            beanFactory.registerResolvableDependency(String.class, "Resolvable Dependency");
        });

        // 要在 refresh 之前加入 resolvable dependency
        ctx.refresh();

        ResolvableDependencyDemo bean = ctx.getBean(ResolvableDependencyDemo.class);
        System.out.println(bean.value);

        ctx.close();
    }
}
